<?php

/**
 * ProveedorNacional form base class.
 *
 * @method ProveedorNacional getObject() Returns the current form's model object
 *
 * @package    dirsac
 * @subpackage form
 * @author     Miguel Flores
 * @version    SVN: $Id: sfDoctrineFormGeneratedTemplate.php 29553 2010-05-20 14:33:00Z Kris.Wallsmith $
 */
abstract class BaseProveedorNacionalForm extends BaseFormDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'id'                => new sfWidgetFormInputHidden(),
      'comuna_id'         => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Comuna'), 'add_empty' => false)),
      'region_id'         => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Region'), 'add_empty' => false)),
      'nombre'            => new sfWidgetFormInputText(),
      'rut'               => new sfWidgetFormInputText(),
      'giro'              => new sfWidgetFormInputText(),
      'telefono'          => new sfWidgetFormInputText(),
      'direccion_web'     => new sfWidgetFormInputText(),
      'calle'             => new sfWidgetFormInputText(),
      'numero'            => new sfWidgetFormInputText(),
      'nombre_contacto'   => new sfWidgetFormInputText(),
      'correo_contacto'   => new sfWidgetFormInputText(),
      'telefono_contacto' => new sfWidgetFormInputText(),
    ));

    $this->setValidators(array(
      'id'                => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
      'comuna_id'         => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Comuna'))),
      'region_id'         => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Region'))),
      'nombre'            => new sfValidatorString(array('max_length' => 255)),
      'rut'               => new sfValidatorString(array('max_length' => 13)),
      'giro'              => new sfValidatorString(array('max_length' => 255)),
      'telefono'          => new sfValidatorString(array('max_length' => 20)),
      'direccion_web'     => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'calle'             => new sfValidatorString(array('max_length' => 255)),
      'numero'            => new sfValidatorInteger(),
      'nombre_contacto'   => new sfValidatorString(array('max_length' => 255)),
      'correo_contacto'   => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'telefono_contacto' => new sfValidatorString(array('max_length' => 255)),
    ));

    $this->validatorSchema->setPostValidator(
      new sfValidatorDoctrineUnique(array('model' => 'ProveedorNacional', 'column' => array('rut')))
    );

    $this->widgetSchema->setNameFormat('proveedor_nacional[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function getModelName()
  {
    return 'ProveedorNacional';
  }

}
